package com.zr.bookcorner.adapter;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.zh.baselibrary.base.BaseRecyclerAdapter;
import com.zh.baselibrary.utils.BitmapHelp;
import com.zh.baselibrary.utils.IntentUtils;
import com.zh.model.manager.BookInfo;
import com.zr.bookcorner.R;
import com.zr.bookcorner.activity.CirCulateActivity;

import java.util.List;

public class BookQueryAdapter extends BaseRecyclerAdapter<BookInfo> {
    public static final int NO_MORE = 0;
    public static final int LOADING_MORE = 1;
    public static final int TO_MORE = 2;
    private int mLoadMoreStatus = 2;

    public BookQueryAdapter(List<BookInfo> mData) {
        super(mData);
    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_quety_book;
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position, BookInfo info) {
        int itemViewType = getItemViewType(position);
        if (itemViewType == 0) {
            BitmapHelp.display((ImageView) holder.getView(R.id.iv_url), info.getImageUrl(), false, R.mipmap.cover);
            setItemText(holder.getView(R.id.tv_auther), info.getAuthor());
            setItemText(holder.getView(R.id.tv_book_name), info.getBookName());
            setItemText(holder.getView(R.id.tv_location), info.getLocation());
            if(info.getStatus()==1){
                holder.getView(R.id.tv_status).setVisibility(View.GONE);
                holder.getView(R.id.tv_status2).setVisibility(View.VISIBLE);
                holder.getView(R.id.tv_status2).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemViewClickListener.onItemViewClick(v,info.getCabinetNum());
                    }
                });
            }else {
                holder.getView(R.id.tv_status).setVisibility(View.VISIBLE);
                holder.getView(R.id.tv_status2).setVisibility(View.GONE);
                if(info.getStatus() ==2){
                    setItemText(holder.getView(R.id.tv_status), "可借阅");
                    ((TextView)holder.getView(R.id.tv_status)).setTextColor(mContext.getResources().getColor(R.color.theme_color));
                }else {
                    setItemText(holder.getView(R.id.tv_status), "已借阅");
                    ((TextView)holder.getView(R.id.tv_status)).setTextColor(mContext.getResources().getColor(R.color.font_black));
                }
            }
        }else {
            holder.getView(R.id.ll_log_content).setVisibility(View.GONE);
            holder.getView(R.id.rl_log_footer).setVisibility(View.VISIBLE);
            switch (mLoadMoreStatus) {
                case NO_MORE:
                    setItemText(holder.getView(R.id.tv_footer_text), "没有更多数据!");
                    break;
                case LOADING_MORE:
                    setItemText(holder.getView(R.id.tv_footer_text), "正在加载...");
                    break;
                case TO_MORE:
                    setItemText(holder.getView(R.id.tv_footer_text), "上拉加载更多!");
                    break;
            }
        }
    }

    public void changeMoreStatus(int status) {
        mLoadMoreStatus = status;
        notifyItemRangeChanged(getItemCount() - 1, getItemCount());
    }
    @Override
    public int getItemCount() {
        return mData == null ? 1 : mData.size()+1;
    }
    @Override
    public int getItemViewType(int position) {
        if (position < mData.size()) {
            return 0;
        }
        return 1;//默认返回表示是尾部的item
    }
}
